const app = getApp();
const api = require("../../utils/api.js");
Page({
  data: {
    img: "",
    swiper: {
      imgUrls: [
        '../../utils/pictures/1.jpg',
        '../../utils/pictures/2.jpg',
        '../../utils/pictures/3.png'
      ],
      indicatorDots: true,//	面板指示圆点
      autoplay: false,//自动播放
        interval: 5000,//每次轮播间隔
        duration: 1000,//轮播动画时长
      current: 0,
    },
  },
 
  scan() {
    wx.scanCode({
      success: (res) => {
        console.log("扫码结果");
        // console.log(res);
        this.setData({
          img: res.result
        })
        // console.log(this.data.img)
      },
      fail: (res) => {
        // console.log(res);
      }
    })

  },
  use() {
    app.globalData.close = true;
    wx.setStorage({
      key: 'close',
      data: {
        flage: true
      },
      success: function (res) {}
    })
    var that = this;
    wx.showLoading({
      title: '正在获取数据',
    });
    api.placeOrder(app.globalData.token, that.data.inputValue)
      .then(res => {
        wx.hideLoading();
        wx.redirectTo({
          url: '../order/order'
        })
      })
      .catch(err => {
        wx.hideLoading();
        wx.showModal({
          title: '操作失败',
          content: err.data.message,
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              // console.log('用户点击确定');
            }
          }
        });
      })
  },
  prevImg: function () {
    var swiper = this.data.swiper;
    var current = swiper.current;
    swiper.current = current > 0 ? current - 1 : swiper.imgUrls.length - 1;
    this.setData({
      swiper: swiper,
    })
  },

  nextImg: function () {
   
    var swiper = this.data.swiper;
    var current = swiper.current;
    swiper.current = current < (swiper.imgUrls.length - 1) ? current + 1 : 0;
    this.setData({
      swiper: swiper,
    })
  },
  onLoad: function (options) {
    var that = this;
    that.setData({
      img: options.img
    })
   
  }
})